import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css';
import { userlogin } from '@/store/user'
const sphRequest = axios.create({
  baseURL: '/sph',
  timeout: 5000
});

sphRequest.interceptors.request.use((config) => {
  nProgress.start();
  /*  const store=userlogin()
 
   const token = store.state.userInfo.token
   if (token) {
     config.headers.token=token
   } */

  const store = userlogin();
  if (store.userInfo.token) {
    config.headers.token = store.userInfo.token //"5ebbb49e3b5047cb8a466c8d27013691"
    config.headers.userTempId = "dfa6a108-45fe-43e2-a7e7-2a560bedb909"
  } else {
    config.headers.token = "5ebbb49e3b5047cb8a466c8d27013691"
  }

  return config;
}, (err) => {
  return Promise.reject(err);
})

sphRequest.interceptors.response.use((response) => {
  nProgress.done();
  return response.data;
}, (err) => {
  return Promise.reject(err);
});

export default sphRequest;